<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button>新闻</button>
  <button>娱乐</button>
  <button>科技</button>
  <button>军事</button>
</body>
<script>
  const btns = document.querySelectorAll('button')
btns.forEach(item=>{
  item.onclick = ()=>{
    // 清除所有按钮的背景颜色
    btns.forEach(v=>{
      v.style.backgroundColor = ''
    })
    // 设置当前点击的按钮背景颜色
   item.style.backgroundColor = 'red'
  }
})
</script>
</html>